<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8">
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <title>登录</title>
        <link rel="stylesheet" href="js/layui/css/layui.css">
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
    </head>

    <body>
        <div class="layui-main" style="width: 500px;">
            <fieldset class="layui-elem-field" style=" margin-top: 200px;">
            <legend th:text = "${sys_name}">CNSY图书管理系统</legend>
            <div class="layui-field-box">
                <form class="layui-form layui-form-pane" action="/login" method="post" >
                    <div class="layui-form-item">
                        <div th:if="${errorMessage!=null}">错误提示：<span class="" style="color:red;" th:text="${errorMessage}"></span></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" name="userName" required="required" lay-verify="username" autocomplete="off" placeholder="请输入用户名" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">密码</label>
                        <div class="layui-input-block">
                            <input type="password"  name="passWord" required="required" lay-verify="pass" autocomplete="off" placeholder="请输入密码"  class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">验证码</label>
                        <div class="layui-input-inline">
                            <input type="text" name="vertifyCode" required="required" lay-verify="imgCode" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width:138px;">
                            <img src="/kaptcha?t=now()" class="layui-img" id = "kaptchaBtn">
                        </div>
                    </div>          
                    <div class="layui-form-item">
                        <button class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="loginFrame">登录</button>
                    </div>
                </form>
            </div>
        </fieldset>
        </div>
    </body>
    <script src="js/layui/layui.js" type="text/javascript"></script>
    <script type="text/javascript">
        layui.use(['element','jquery','form'], function(){
    	    var element = layui.element;
    	    var $ = layui.jquery;
    	    const form = layui.form;
    	    
    	    $(document).on('click','#kaptchaBtn',function(){
    	    	$("#kaptchaBtn").attr("src","/kaptcha?t="+new Date());
    	    });
    	    
    	    form.verify({
    	        username: [
                    /^[\S]{5,12}$/
                    ,'用户名必须5到12位，且不能出现空格'
                  ]
    	        ,pass: [
    	          /^[\S]{5,12}$/
    	          ,'密码必须5到12位，且不能出现空格'
    	        ],imgCode:function(value){
    	        	const flag = false;
    	        	$.ajax({
    	        		url:"/imgCode/validate",
    	        		type:"post",
    	        		data:{
    	        			imgCode:value
    	        		},
    	        		async:false,
    	        		dataType:"json",
    	        		success:function(data){
    	        			if(data.code == 1){
    	        				flag = true;
    	        			}
    	        		}
    	        	});
    	        	if(flag){
    	        	    return "验证码输入错误";
    	        	}
    	        }
    	      });
    	    
    	    
    	});
    
    </script>

</html>